﻿<!DOCTYPE html>
<html>
	<head>
		<title>链接添加修改</title>
    $css()$js()
	</head>
	<body>
    <style type="text/css">
        #bind{width:300px;position:absolute;left:350px;top:20px;line-height:30px;}
        .archivelist{line-height:20px;}
    </style>
    
    <form action="" method="post">
	

    <div class="area">
        <div class="form">
  <!--<dl><dt>链接类型：</dt><dd>
  <select class=" ui-validate" required="true" summary="{required:'请选择类型'}" name="type" id="linkType">
  <option value="">一请选择链接类型一</option>
  <option value="3"> 自定义链接 </option>
  <option value="1"> 网站导航 </option>
  <option value="2"> 友情链接 </option></select>
  </dd></dl>-->
  <input type="hidden" name="linkType" value="${linkType}" />
  <input type="hidden" name="linkid" value="${linkid}" />

  <dl><dt>绑定:</dt><dd>
  <input type="hidden" name="bindid" id="bindid" value="${bindid}"/>
  <input type="hidden" name="bindtype" id="bindtype" value="${bindtype}"/>

  <span id="bindtip">${bindTitle}</span>&nbsp;&nbsp;
  <a href="javascript:cancelBind()" id="cancelbind">取消绑定</a>

  </dd></dl>
  <dl><dt>文&nbsp;&nbsp;&nbsp;&nbsp;字：</dt><dd><input type="text" class=" ui-validate" required="true" length="[0,50]" name="text" id="text"/><script type="text/javascript">cms.$('text').value = '${linkText}';</script></dd></dl>
  <dl id="urlpanel"><dt>地&nbsp;&nbsp;&nbsp;&nbsp;址：</dt><dd><input type="text" class=" ui-validate" length="[0,255]" name="uri" id="uri" size="45" value="${linkUri}" /><br /><span class="msg" style="color:#777;font-size:smaller;padding-left:65px;">路径请以"/"开头,外站链接请加"http://"</span></dd></dl>
 <dl><dt>图片：</dt><dd><input type="text" class=" ui-validate" length="[0,100]" name="imgurl" id="imgurl" value="${imgurl}" tipin="imgurl_tip"/>
   <span id="imgurl_tip">选填</span>
   <div style="display:block;padding-left:55px;"><span id="upload">上传文件</span></div>
 
   </dd></dl>
  <dl><dt>顺&nbsp;&nbsp;&nbsp;&nbsp;序：</dt><dd><input type="text" class=" ui-validate" isnumber="true" name="index" id="index" style="width:30px" value="${linkIndex}"/><span class="msg">显示的顺序,如:1</span></dd></dl>
  <dl><dt>打开方式：</dt><dd><span class="input"><select class="tb_normal" name="target" id="linkTarget"><option value="">本窗口</option><option value="_blank">新窗口</option></select></span></dd></dl>
  <dl><dt>&nbsp;</dt><dd><a id="btn" class="btn" href="javascript:;">${btnText}</a></dd></dl>




</div>

<div id="bind">
  继承于:<br /><select name="pid" id="pid"><option value="0">一不继承一</option>${plinks}</select>
  <br />

  绑定分类:<br />
  <div> 
  <select name="categoryid" class="left">
                    <option value="">一请选择栏目一</option>
                    ${categoryNodes}
                </select><a class="btn" href="javascript:;" onclick="bind({id:this.previousSibling.value,text:this.previousSibling.options[this.previousSibling.selectedIndex].innerHTML,type:'category'});return false;">绑定</a>

                </div>

  <div class="clearfix">
    绑定文档:
  </div>
  <input type="text" id="title" class="left"/><a class="btn" onclick="searchArchive('title');" href="javascript:;">搜索</a>
  <div class="archivelist clearfix">
    
  </div>

</div>

    </div>

  </form>
  <script type="text/javascript">

      var bindid = cms.$('bindid'),
            bindtype = cms.$('bindtype'),
            bindtip = cms.$('bindtip'),
            cancelbind = cms.$('cancelbind'),
            linkurl = cms.$('urlpanel');

      cancelbind.style.display = bindtip.innerHTML == '未绑定' ? 'none' : '';
      linkurl.style.display = cancelbind.style.display != 'none' ? 'none' : '';

      var upload = cms.upload({
          id: 'upload',
          url: '?module=upload&action=uploadimage&for=link&upload.id=upload',
          exts: '*.gif;*.jpg;*.png;*.bmp'
      }, function (path) {
          cms.$('imgurl').value = path;
          //cms.$('thumbnail_img').src = path;
      });

      function searchArchive(id) {
          var key = cms.val(id);
          var panel = document.getElementsByClassName('archivelist')[0];
          if (key != '') {

              panel.innerHTML = '获取搜索结果...';
              cms.xhr.post('?', 'module=ajax&action=GetSearchArchivesJsonResult&key=' + encodeURIComponent(key), function (result) {
                  var data = cms.toJson(result);
                  panel.innerHTML = '';
                  for (var i = 0; i < data.length; i++) {
                      var ele = document.createElement("DIV");
                      ele.innerHTML = data[i].title.replace(key,'<span style="color:red">'+key+'</span>') + '<a href="javascript:bind({id:\'' + data[i].id + '\',text:\'' + data[i].title + '\',type:\'archive\'})">绑定</a>';
                      panel.appendChild(ele);
                  }
              }, function () {
                  panel.innerHTML = '<span>获取搜索结果异常!</span>';
              });
          }
      }

      function bind(data) {
          var id = data.id,
            text = data.text,
            type = data.type;

          if (id != '') {
              var typeStr = '';
              switch (type) {
                  case 'archive': typeStr = '文档'; break;
                  case 'category': typeStr = '栏目'; break;
              }

              bindid.value = id;
              bindtype.value = type;
              bindtip.innerHTML = typeStr + ':' + text;
              cms.$('cancelbind').style.display = '';
              linkurl.style.display = 'none';
          }
      }


      function cancelBind() {
          bindid.value = '';
          bindtype = '';
          bindtip.innerHTML = '未绑定';
          cms.$('cancelbind').style.display = 'none';
          linkurl.style.display = '';
      }


    
     document.getElementById('linkTarget').value = '${linkTarget}';
     cms.$('pid').value = '${pid}';

     cms.$('btn').onclick = function onsubmit() {

         var isEdit = location.hash.split('.')[1] == 'edit';

         if (cms.validator.validate()) {
             cms.xhr.jsonAjax(
                    isEdit ? '?module=link&action=edit' : '?module=link&action=create'
                    , cms.form.getData()
                    , function (json) {
                        if (json.result) {
                            parent.M.alert(json.message, function () {
                                    location.replace('?module=link&action=list&type=${type}');
                               
                            });

                        } else {
                            cms.dialog.alert(json.message);
                        }

                    });

         }
     };
  </script>
	</body>
</html>